package qa.tools.controller;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import qa.tools.commom.ApiResult;
import qa.tools.model.po.AutoResult;
import qa.tools.model.vo.AutoResultVo;
import qa.tools.service.AutoResultService;

import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author LiJiang
 * @since 2021-09-08
 */
@Tag(name = "接口自动化结果展示")
@RestController
@Slf4j
@RequestMapping("result")
public class AutoResultController {

    @Autowired
    AutoResultService AutoResultService;

    @Operation(summary = "搜索-分页")
    @PostMapping("/search")
    public ApiResult queryApiResult(@RequestBody AutoResultVo autoResultVo) {

        Map<String, Object> map = AutoResultService.queryApiResult(autoResultVo);

        return ApiResult.succeedWith(map, "搜索查询成功");
    }


    @Operation(summary = "单个详情页")
    @GetMapping("/{id}")
    public ApiResult queryBid(@PathVariable Long id) {

        AutoResult byId = AutoResultService.getById(id);

        return ApiResult.succeedWith(byId, "查询成功");
    }

    @Operation(summary = "分页查询所有")
    @GetMapping("/page/{current}/{size}")
    public ApiResult resultAll(@PathVariable Long current,
                               @PathVariable Long size) {

        Map<String, Object> map = AutoResultService.queryAll(current, size);

        return ApiResult.succeedWith(map);
    }


}

